import Cookies from 'js-cookie'
import config from '@/config'
const { TOKEN_KEY, COOKIE_EXPIRES } = config

/**
 * @param {String} token token
 * @description 将token缓存到cookie中
 */
export const setToken = (token) => {
  Cookies.set(TOKEN_KEY, token, { expires: COOKIE_EXPIRES || 1 })
}

export const getToken = () => {
  const token = Cookies.get(TOKEN_KEY)
  return token || false
}

/**
 * @description 设置cookie
 */
export const setCookie = (cookieName, cookieValue, times) => {
  Cookies.set(cookieName, cookieValue, { expires: times })
}

export const getCookie = (cookieName) => {
  return Cookies.get(cookieName)
}

export const removeCookie = (cookieName) => {
  Cookies.remove(cookieName)
}
